<html>
<head></head>
<body>
<?php
require_once dirname(__FILE__) . '/includes/common.inc.php';
require_once dirname(__FILE__) . '/includes/pdoorm.inc.php';

//header('Content-Type: text/plain');

if (isset($_COOKIE[OPERATOR])) { 
 $coperator = json_decode($_COOKIE[OPERATOR]);
}

try {
  $wd = MiscUtils::getParam('wd', NULL);
  $co = MiscUtils::getParam('countonly', NULL);
  //$u = MiscUtils::getParam('u', NULL);
  $u = MiscUtils::getParam('u', json_encode(array()));
  $u = json_decode($u);
  $user=isset($u->user)? $u->user : '';
  $pass=isset($u->pass)? $u->pass : '';  
  
  $now = SimpleDate::fromStamp($wd + LAG);
  
  $sql=" SELECT distinct c.e_oid,c.bridename,c.bridemobile,c.groomname,c.groommobile FROM ns_v1myorder AS m LEFT JOIN ns_v1customer AS c ON m.customerId=c.e_oid
         WHERE 1=1 and LEFT(FROM_UNIXTIME(m.date),10)='{$wd}'";
  
  $tmp=getall($sql,1);
  $count = count_num($sql);
  
 if(empty($co))
 { 
  $strtable ="<table cellpadding='0' cellspacing='0' style=\"width:990px; border-left:solid 1px #ddd;border-top:solid 1px #ddd\";>";
  $strtable .="<tr style=\"font-weight:bold;background-color:#dcaaaa;height:30px; font-size:13px\">";
  $strtable .="<td width='20%' style=\"border-right:solid 1px #fff;padding-left:5px;\";>Customer No</td>";
  $strtable .="<td width='20%' style=\"border-right:solid 1px #fff;padding-left:5px;\";>Bride</td>";
  $strtable .="<td width='20%'  style=\"border-right:solid 1px #fff;padding-left:5px;\";>Mob</td>";
  $strtable .="<td width='20%'  style=\"border-right:solid 1px #fff;padding-left:5px;\";>Groom</td>";
  $strtable .="<td width='20%'  style=\"border-right:solid 1px #fff;padding-left:5px;\";>Mob</td>";
  $strtable .="</tr>";
  
  
  if(!empty($tmp))
  {
  	foreach($tmp as $t)
  	{
  		//href=\"$syspath$gurl\"
  		$syspath="http://".DOMAIN.PATH;
  		$cid=$t['e_oid'];
  		$gurl="/?p=pageadmin&t=pagecustomerold&m={%22a%22:2,%22b%22:1}&opts={%22id%22:%22{$cid}%22}&u={%22user%22:%22{$user}%22,%22pass%22:%22{$pass}%22}";
  		$cno="<a  href='$syspath$gurl' onclick=\"chknull('".$user."','".$pass."','$syspath$gurl');\" target='_blank'>".customerno($t['e_oid'])."</a>";
  		$t['bridename'] = $t['bridename']=='' ? '&nbsp;' : $t['bridename'];
        $t['bridemobile'] = $t['bridemobile']=='' ? '&nbsp;' : $t['bridemobile'];
        $t['groomname'] = $t['groomname']=='' ? '&nbsp;' : $t['groomname'];
        $t['groommobile'] = $t['groommobile']=='' ? '&nbsp;' : $t['groommobile'];
	  $strtable .="<tr style=\"height:30px; border:1px solid #ddd; font-size:12px\">";
	  $strtable .="<td width='20%' style=\"border-right:solid 1px #ddd;border-bottom:solid 1px #ddd;padding-left:5px;\";>".$cno."</td>";
	  $strtable .="<td width='20%' style=\"border-right:solid 1px #ddd;border-bottom:solid 1px #ddd;padding-left:5px;\";>".$t['bridename']."</td>";
	  $strtable .="<td width='20%' style=\"border-right:solid 1px #ddd;border-bottom:solid 1px #ddd;padding-left:5px;\";>".$t['bridemobile']."</td>";
	  $strtable .="<td width='20%' style=\"border-right:solid 1px #ddd;border-bottom:solid 1px #ddd;padding-left:5px;\";>".$t['groomname']."</td>";
	  $strtable .="<td width='20%' style=\"border-right:solid 1px #ddd;border-bottom:solid 1px #ddd;padding-left:5px;\";>".$t['groommobile']."</td>";
	  $strtable .="</tr>";  
  	}	
  }else{
  $strtable .="<tr>";
  $strtable .="<td colspan=\"6\" align='center' style=\"border-right:solid 1px #ddd;border-bottom:solid 1px #ddd;\";>N/A</td>";
  $strtable .="</tr>"; 	
  }
  
  $strtable .="</table>";
  
  echo $strtable;
 }else{
 	 echo "<div style=\"margin:-6px 0 0 -8px; color:#a7345e;font-size:12px;\">(".$count.")</div>";
 }
} catch (PDOException $e) {
  echo $e->getMessage();
}
?>
<script type="text/javascript">
function chknull(user,pass,url)
{
	if(user=='' || pass=='')
	{
		window.alert('user or pass is empty');
		//return false;
		//location.href = url;
		return false;
	}

	//location.href = url;

	return true;
   
}

</script>
</body>
</html>